package com.juc.phaser.phaser11;

import java.util.concurrent.Phaser;

public class ThreadA extends Thread{
	/**
	 * awaitAdvance(int phase) 如果传入参数phase值和当前
	 * getPhase()返回值一样，则在屏障处等待，否则继续向下面运行，
	 * 有些类似旁观者的作用，当观察的条件满足了就等待（旁观），
	 * 如果条件不满足，则程序继续向下执行
	 */
	/**
	 * 	
		try {
			System.out.println(Thread.currentThread().getName() + " A1 begin = " +System.currentTimeMillis());
			Thread.sleep(3000);
			phaser.awaitAdvance(0);//跨栏的栏数
			System.out.println(Thread.currentThread().getName() + " A1 end = " +System.currentTimeMillis());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	 */
	private Phaser phaser;
	
	public ThreadA(Phaser phaser) {
		super();
		this.phaser = phaser;
	}

	@Override
	public void run() {
		System.out.println(Thread.currentThread().getName() + " A1 begin = " +System.currentTimeMillis());
		phaser.arriveAndAwaitAdvance();
		System.out.println(Thread.currentThread().getName() + " A1 end = " +System.currentTimeMillis());

	}
}
